/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.gob.pnp.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import pe.gob.pnp.beans.ParentescoBean;
import pe.gob.pnp.factories.ConnectionPool;

/**
 *
 * @author Greco
 */
public class GestionParentesco {

    public List<ParentescoBean> obtenerParentesco() throws SQLException {
        List<ParentescoBean> lstParentesco = new ArrayList<ParentescoBean>();
        Connection conn = null;
        try {
            conn = ConnectionPool.obtenerConexion();
            String sql = "SELECT NPARE_IDENTIFICADOR,CPARE_DESCRIPCION ";
            sql += " FROM DIRPEN.GENMA_PARENTESCO";
            sql += " WHERE BPAR_ELIMINADO=0";
            sql += " ORDER BY CPARE_DESCRIPCION";
            PreparedStatement ps = conn.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                ParentescoBean obj = new ParentescoBean();
                obj.setNpareIdentificador(rs.getInt("NPARE_IDENTIFICADOR"));
                obj.setCpareDescripcion(rs.getString("CPARE_DESCRIPCION"));
                lstParentesco.add(obj);
            }
            rs.close();
            ps.close();
        } catch (Exception err) {
            err.printStackTrace();
        } finally {
            ConnectionPool.liberarConexion(conn);
        }
        return lstParentesco;
    }
}
